/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include <boost/scoped_ptr.hpp>
#include "TextureSimple.h"

namespace liba
{
namespace lib3d
{
namespace material
{

class TextureReflectionRep : public HardwareDependentObject<hard::Manager, hard::TextureCubic>, public SharedPrecachedRepBase
{
public:
	TextureReflectionRep(const TextureSimpleName & name)
	:	pl( 0 )
	{
		hard::Manager::add_dependent( this );
	}
	~TextureReflectionRep()
	{
		hard::Manager::remove_dependent( this );
	}
	void load(const TextureSimpleName & name);
	void render_to_list( hard::Hardware * hardware, hard::RenderTexture * render_texture );
protected:
	virtual void on_add_hardware(hard::Manager::hardware_type * ha);
private:
	boost::scoped_ptr<pictureformat::Loader> pl;
};

class TextureReflection : public Texture, public SharedPrecached<TextureSimpleName, TextureReflectionRep>
{
public:
	typedef name_type Name;
	TextureReflection(const Atom & animate_node_name, const TextureSimpleName & name)
	:	Texture(animate_node_name, name.wrap)
	{
		load_rep(name);
	}
	virtual TextureReflection * clone()const;

	virtual void render_to_list( hard::Hardware * hardware, hard::RenderTexture * render_texture )
	{
		Texture::render_to_list( hardware, render_texture );
		return get_rep()->render_to_list( hardware, render_texture );
	}
};


} // namespace material
} // namespace lib3d
} // namespace liba
using namespace liba;

